/*
 * Copyright (c) 2002-2004, Inversoft, All Rights Reserved
 *
 * This software is distribuable under the GNU Lesser General Public License.
 * For more information visit gnu.org.
 */
package org.emergent.antbite.savant;


import java.io.File;


/**
 * <p>
 * This class is a workflow process that attempts to download
 * artifacts from the internet using the Savant scheme via HTTP.
 * </p>
 *
 * <p>
 * Savant's URL scheme is
 * <b>domain</b>/<b>group</b>/<b>project</b>/<b>name</b>-<b>version</b>.<b>type</b>
 * </p>
 *
 * <p>
 * Savant's scheme allows a local repository to be setup and
 * still contain artifacts from 3rd party groups.
 * </p>
 *
 * <p>
 * In order to determine the domain in the URL, either a
 * properties file can be read for group/domain pairs. Or
 * a standard location can be setup in this class.
 * </p>
 *
 * @author  Brian Pontarelli
 */
public class SavantInternetProcess extends InternetProcess {

    private static final URLBuilder builder = new SavantURLBuilder();


    /**
     * <p>
     * Using a simple URL connection, this attempts to download the artifact
     * dependency XML file, parse it and update the given artifacts internal
     * list of dependencies. This is done using standard Savant URLs. If the
     * artifact dependencies are found, they are cached locally using the
     * LocalCacheStore.
     * </p>
     *
     * @param   artifact The artifact to update with the resolved dependencies.
     * @return  True if the artifact was updated, false otherwise.
     */
    public boolean resolveArtifactDependencies(Artifact artifact,
            LocalCacheStore localCache)
    throws SavantException {
        return resolveArtifactDependencies(builder, artifact, localCache);
    }

    /**
     * Using a simple URL connection, this grabs the date of the URL resource and
     * then attempts to store the stream from the URL to the local cache.
     *
     * @param   artifact The artifact to store
     * @param   localCache The local cache to store the artifact in
     * @return  The File if downloaded and stored
     */
    public File fetch(Artifact artifact, LocalCacheStore localCache)
    throws SavantException {
        return findFile(builder, artifact, localCache);
    }

    /**
     * Returns SavantProcess.
     */
    public String getProcessName() {
        return "SavantProcess";
    }
}